<!DOCTYPE HTML>
<html>
  <head>
    <title>{{$.Dashboard.Name}} Build Dashboard</title>
    <link rel="stylesheet" href="/static/style.css"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script>
    var showUnsupported = window.location.hash.substr(1) != "short";
    function redraw() {
        showUnsupported = !$("#showshort").prop('checked');
        $('.unsupported')[showUnsupported?'show':'hide']();
        window.location.hash = showUnsupported?'':'short';
    }
    $(document).ready(function() {
        $("#showshort").attr('checked', !showUnsupported).change(redraw);
        redraw();
    })
    </script>
  </head>

  <body>
    <header id="topbar">
      <h1>Go Dashboard</h1>
      <div class="clear"></div>
    </header>

    <form action="." method="GET">
    <input type="hidden" name="repo" value="{{.Package.Path}}">
    <nav class="dashboards">
      {{if not (eq .Branch "")}}
      <label>
        <select name="branch" onchange="this.form.submit()">
        {{range $.Branches}}
          <option value="{{.}}"{{if eq $.Branch .}} selected{{end}}>{{.}}</option>
        {{end}}
        </select>
      </label>
      {{end}}
      <label>
        <input type=checkbox id="showshort">
        show only <a href="http://golang.org/wiki/PortingPolicy">first-class ports</a>
      </label>
    </nav>
    </form>
    {{with $.Package.Name}}<h2>{{.}}</h2>{{end}}

  <div class="page">

    {{if $.Commits}}

    <table class="build">
      <colgroup class="col-hash" {{if $.Package.Path}}span="2"{{end}}></colgroup>
      <colgroup class="col-user"></colgroup>
      <colgroup class="col-time"></colgroup>
      <colgroup class="col-desc"></colgroup>
    {{range $.Builders | builderSpans}}
      <colgroup class="col-result{{if .Unsupported}} unsupported{{end}}" span="{{.N}}"></colgroup>
    {{end}}
      <tr>
        <!-- extra row to make alternating colors use dark for first result -->
      </tr>
      <tr>
    {{if $.Package.Path}}
        <th colspan="2">revision</th>
    {{else}}
        <th>&nbsp;</th>
    {{end}}
        <th></th>
        <th></th>
        <th></th>
    {{range $.Builders | builderSpans}}
        <th {{if .Unsupported}}class="unsupported"{{end}} colspan="{{.N}}">{{.OS}}</th>
    {{end}}
      </tr>

      <tr>
    {{if $.Package.Path}}
        <th class="result arch">repo</th>
        <th class="result arch">{{$.Dashboard.Name}}</th>
    {{else}}
        <th>&nbsp;</th>
    {{end}}
        <th></th>
        <th></th>
        <th></th>
    {{range $.Builders}}
        <th class="result arch{{if (unsupported .)}} unsupported{{end}}{{if knownIssue .}} noise{{end}}" title="{{.}}">{{builderSubheading .}}</th>
    {{end}}
      </tr>

      <tr class="subheading2">
        <th {{if $.Package.Path}}colspan="2"{{end}}>&nbsp;</th>
        <th></th>
        <th></th>
        <th></th>
    {{range $.Builders}}
        <th class="result arch{{if (unsupported .)}} unsupported{{end}}{{if knownIssue .}} noise{{end}}" title="{{.}}">{{builderSubheading2 .}}</th>
    {{end}}
      </tr>

      {{range $c := $.Commits}}
      {{range $i, $h := $c.ResultGoHashes}}
        <tr class="commit">
        {{if $i}}
          <td>&nbsp;</td>
        {{if $h}}
          <td class="hash"><a href="https://go-review.googlesource.com/q/{{$h}}">{{shortHash $h}}</a></td>
        {{end}}
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        {{else}}
          <td class="hash"><a href="https://go-review.googlesource.com/q/{{$c.Hash}}">{{shortHash $c.Hash}}</a></td>
        {{if $h}}
          <td class="hash"><a href="https://go-review.googlesource.com/q/{{$h}}">{{shortHash $h}}</a></td>
        {{end}}
          <td class="user" title="{{$c.User}}">{{shortUser $c.User}}</td>
          <td class="time">{{formatTime $c.Time}}</td>
          <td class="desc" title="{{$c.Desc}}">{{shortDesc $c.Desc}}</td>
        {{end}}
          {{range $builderName := $.Builders}}
            <td class="result{{if (unsupported .)}} unsupported{{end}}">
            {{if isUntested $builderName "go" $.Branch ""}}•{{else}}
              {{with $c.Result $builderName $h}}
                {{if .BuildingURL}}
                  <a href="{{.BuildingURL}}"><img src="https://golang.org/favicon.ico" height=16 width=16 border=0></a>
                {{else if .OK}}
                  <span class="ok{{if knownIssue $builderName}} noise{{end}}">ok</span>
                {{else if knownIssue $builderName}}
                  <a href="/log/{{.LogHash}}" class="noise" title="Builder {{$builderName}} has a known issue. See golang.org/issue/{{knownIssue $builderName}}.">fail</a>
                {{else}}
                  <a href="/log/{{.LogHash}}" class="fail">fail</a>
                {{end}}
              {{else}}
                &nbsp;
              {{end}}
            {{end}}
            </td>
          {{end}}
        </tr>
      {{end}}
    {{end}}
    </table>

    {{with $.Pagination}}
    <div class="paginate">
      <nav>
        <a {{if .HasPrev}}href="?{{with $.Package.Path}}repo={{.}}&{{end}}page={{.Prev}}{{with $.Branch}}&branch={{.}}{{end}}"{{else}}class="inactive"{{end}}>newer</a>
        <a {{if .Next}}href="?{{with $.Package.Path}}repo={{.}}&{{end}}page={{.Next}}{{with $.Branch}}&branch={{.}}{{end}}"{{else}}class="inactive"{{end}}>older</a>
        <a {{if .HasPrev}}href=".{{with $.Branch}}?branch={{.}}{{end}}"{{else}}class="inactive"{{end}}>latest</a>
      </nav>
    </div>
    {{end}}

  {{else}}
    <p>No commits to display. Hm.</p>
  {{end}}

  {{range $.TagState}}
    {{$goHash := .Tag.Hash}}
    {{$goBranch := .Branch}}
    {{$builders := .Builders}}
    {{if .Packages}}
      <h2>
        golang.org/x repos at Go {{$goBranch}}
        <small>(<a href="https://go-review.googlesource.com/q/{{.Tag.Hash}}">{{shortHash .Tag.Hash}}</a>)</small>
      </h2>

      <table class="build">
      <colgroup class="col-package"></colgroup>
      <colgroup class="col-hash"></colgroup>
      <colgroup class="col-user"></colgroup>
      <colgroup class="col-time"></colgroup>
      <colgroup class="col-desc"></colgroup>
      {{range $builders | builderSpans}}
        <colgroup class="col-result{{if .Unsupported}} unsupported{{end}}" span="{{.N}}"></colgroup>
      {{end}}
      <tr>
        <!-- extra row to make alternating colors use dark for first result -->
      </tr>
      <tr>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        {{range $builders | builderSpans}}
          <th {{if .Unsupported}}class="unsupported"{{end}} colspan="{{.N}}">{{.OS}}</th>
        {{end}}
      </tr>
      <tr>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        {{range $builders}}
          <th class="result arch{{if (unsupported .)}} unsupported{{end}}" title="{{.}}">{{builderSubheading .}}</th>
        {{end}}
      </tr>
      <tr class="subheading2">
        <th>&nbsp;</th>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        {{range $builders}}
          <th class="result arch{{if (unsupported .)}} unsupported{{end}}" title="{{.}}">{{builderSubheading2 .}}</th>
        {{end}}
      </tr>
    {{range $pkg := .Packages}}
      <tr class="commit">
        <td><a title="{{.Package.Path}}" href="?repo={{.Package.Path}}">{{.Package.Name}}</a></td>
        <td class="hash">
          {{$h := $pkg.Commit.Hash}}
          <a href="https://go-review.googlesource.com/q/{{$h}}">{{shortHash $h}}</a>
        </td>
        {{with $pkg.Commit}}
          <td class="user" title="{{.User}}">{{shortUser .User}}</td>
          <td class="time">{{formatTime .Time}}</td>
          <td class="desc" title="{{.Desc}}">{{shortDesc .Desc}}</td>
        {{end}}
        {{range $builderName := $builders}}
          <td class="result{{if (unsupported .)}} unsupported{{end}}">
            {{if isUntested $builderName $pkg.Package.Name "master" $goBranch}}
              •
            {{else}}
              {{with $pkg.Commit.Result $builderName $goHash}}
                {{if .BuildingURL}}
                  <a href="{{.BuildingURL}}"><img src="https://golang.org/favicon.ico" height=16 width=16 border=0></a>
                {{else if .OK}}
                  <span class="ok">ok</span>
                {{else}}
                  <a href="/log/{{.LogHash}}" class="fail">fail</a>
                {{end}}
              {{else}}
                &nbsp;
              {{end}}
            {{end}}
          </td>
        {{end}}
      </tr>
    {{end}}
    </table>
   {{end}}
  {{end}}

  </div>
  </body>
</html>
